package com.tcp;

import java.net.*;
import java.io.*;
import java.util.HashMap;

public class TCPServer {
    public static void main(String[] args) {
        ServerSocket ss = null;
        HashMap<String, Socket> clients = new HashMap<String, Socket>();
        try {
            ss = new ServerSocket(1025);//监听端口6666
            while (true) {
                Socket s = ss.accept(); // accept 阻塞式的 等待客户端链接过来
                System.out.println(s.getInetAddress().getHostAddress() + ":" + s.getPort() + " connect!");
                if (s.getInetAddress().getHostAddress().equals("192.168.0.101")) {//GNSS
                    System.out.println("检测到GNSS");
                    clients.put("gnss", s);
                } else {//NtripServer
                    System.out.println("检测到NtripServer");
                    clients.put("ns", s);
                }
                new Thread(new TransferInfo(clients.get("gnss"), clients.get("ns"))).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (ss != null) {
                try {
                    ss.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}


